Question one: Can Java constructors be inherited?The author of Java read a book said: "Java subclasses naturally inherit its superclass" non-private members.Normally Java constructors are set to public (if you do not write the constructor, Java
Statement: Just touch Java soon, if you understand there are errors or deviations look at the strong criticism of the big guyCan the Java subclass inherit the constructor of the parent class?Parent Class Code:1 classFather {2String name;//it's not
In Java, the constructor of the parent class must be called during the subclass construction process because when there is an inheritance relationship, the Child class must inherit the content of the parent class, by what means?
The answer is as
Recently learned to inherit, from the book to see the subclass inherit the parent class, the subclass has all the parent class properties and methods, and then use the program to verify that the parent class's private properties and private methods,
In Java inheritance, constructor is not inherited, but called (implicitly or explicitly ).
The following is an example:
Public class fatherclass {
Public fatherclass (){System. Out. println (100 );}
Public fatherclass (INT age ){System. Out.
Package com.hanwei.service;
Class testparent{public
testparent () {
System.out.println ("I am a parameterless constructor for the parent class");
}
Public Testparent (String a) {
System.out.println
Summary of constructor methods in Java today's code writing suddenly found that Java constructor also has a lot of arguments, nothing to worry about. Summary: The difference between constructor methods and instance methods: i. The main difference
Source: http://www.cnblogs.com/sunnychuh/archive/2011/09/09/2172131.html---------------------Java inheritance does not inherit from constructors, just calls (implicit or explicit).Here is an example:public class Fatherclass {Public Fatherclass ()
Interfaces can inherit Interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit concrete Classes. There can be static main methods in an abstract class.Q: Does an abstract class inherit entity classes
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.